]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Example Assets/portraits/CustomPortrait_FaceAtlas.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Example Assets / portraits / CustomPortrait_FaceAtlas.gd
1 @tool
2 extends DialogicPortrait
3
4 enum Faces {BASED_ON_PORTRAIT_NAME, NEUTRAL, HAPPY, SAD, JOY, SHOCK, ANGRY}
5
6 @export var emotion: Faces = Faces.BASED_ON_PORTRAIT_NAME
7 @export var portrait_width: int
8 @export var portrait_height: int
9 @export var alien := true
10
11 var does_custom_portrait_change := true
12
13 func _ready() -> void:
14         $Alien.hide()
15
16
17 # Function to accept and use the extra data, if the custom portrait wants to accept it
18 func _set_extra_data(data: String) -> void:
19         if data == "alien":
20                 $Alien.show()
21         elif data == "no_alien":
22                 $Alien.hide()
23
24
25 # This function can be overridden. Defaults to true, if not overridden!
26 func _should_do_portrait_update(_character: DialogicCharacter, _portrait:String) -> bool:
27         return true
28
29
30 # If the custom portrait accepts a change, then accept it here
31 func _update_portrait(_passed_character: DialogicCharacter, passed_portrait: String) -> void:
32         for face in $Faces.get_children():
33                 face.hide()
34
35         if emotion == Faces.BASED_ON_PORTRAIT_NAME:
36                 if 'happy' in passed_portrait.to_lower(): $Faces/Smile.show()
37                 elif 'sad' in passed_portrait.to_lower(): $Faces/Frown.show()
38                 elif 'joy' in passed_portrait.to_lower(): $Faces/Joy.show()
39                 elif 'shock' in passed_portrait.to_lower(): $Faces/Shock.show()
40                 elif 'angry' in passed_portrait.to_lower(): $Faces/Anger.show()
41                 else: $Faces/Neutral.show()
42
43         else:
44                 if emotion == Faces.HAPPY: $Faces/Smile.show()
45                 elif emotion == Faces.SAD: $Faces/Frown.show()
46                 elif emotion == Faces.JOY: $Faces/Joy.show()
47                 elif emotion == Faces.SHOCK: $Faces/Shock.show()
48                 elif emotion == Faces.ANGRY: $Faces/Anger.show()
49                 else: $Faces/Neutral.show()
50
51         $Alien.visible = alien
52
53
54 func _set_mirror(is_mirrored: bool) -> void:
55         if is_mirrored:
56                 self.scale.x = -1
57
58         else:
59                 self.scale.x = 1
60
61
62 ## If implemented, this is used by the editor for the "full view" mode
63 func _get_covered_rect() -> Rect2:
64         # This will focus on the face.
65         # return Rect2($Faces/Anger.position+$Faces.position, $Faces/Anger.get_rect().size*$Faces/Anger.scale*$Faces.scale)
66         var size: Vector2 = $Body.get_rect().size
67         var scaled_size: Vector2 = size * $Body.scale
68         var position: Vector2 = $Body.position
69
70         return Rect2(position, scaled_size)